//
//  DDBottomBar.swift
//  SinaWeibo
//
//  Created by mac on 16/1/11.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class DDBottomBar: UITabBar {
     var btn : UIButton
    
    
    
    override init(frame: CGRect) {
        btn = UIButton()
        super.init(frame: frame)
        btn.setImage(UIImage(named:"tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        let img = UIImage(named: "tabbar_compose_button_highlighted")
         btn.setBackgroundImage(img, forState: UIControlState.Highlighted)
        addSubview(btn)
          btn.sizeToFit()
        
        
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        print(self.bounds)
        var index : CGFloat = 0
        let x : CGFloat = 0
        let y :CGFloat = 0
        
        let w = self.bounds.width/5
        let h = self.bounds.height
        
        let rect = CGRectMake(x, y, w,h)
        
        
        for btns in subviews {
            //为什么不行？？
            if btns.isKindOfClass(NSClassFromString("UITabBarButton")!){
                btns.frame = CGRectOffset(rect, index * w, 0)
                
                if index == 1{
                    
                    index++
                    btn.frame = CGRectOffset(rect, index * w, 0)
                    
                }
                index++

              
            }
            
            
        }
        
        
        
        
        
    }
  

}
